// Copyright(C) Japan Android Group Gunma
// LGPL License
// Writers Rabbit-U

package jp.android_group.gunma.gunma_app_lib;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class TwitterActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.twitter);

		String city;
		
		{
			Intent intent = getIntent();
			city = intent.getStringExtra("city");
		}

		m_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

		{
			CityInfo info = CityInfo.getCityInfo(city);
			
			for( String tag : info.m_listTwitterHashTag ) {
				m_adapter.add(tag);
			}
		}
		
		{
			ListView v = (ListView)findViewById(R.id.ListViewHashTag);
			v.setAdapter(m_adapter);
			v.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View item, int pos, long id) {
					
					TwitterActivity.this.onItemClick(pos);
					
				}
				
			});
		}
		
	}
	
	ArrayAdapter<String> m_adapter;
	
	void onItemClick(int pos) {

		Uri uri;
		
		{
			String tag = m_adapter.getItem(pos);
			String strUri = "http://twitter.com/#!/search/" + Uri.encode(tag);
			uri = Uri.parse(strUri);
		}
		
		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_VIEW);
		intent.setData(uri);
		startActivity(intent);

	}

}
